import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import layout from '@/layout'

/* Layout */
import problemPage from './modules/problemPage'
import systemManagement from './modules/systemManagement'
import tableManagement from './modules/tableManagement'
import fileTable from './modules/fileTable'
import deviceManagement from './modules/deviceManagement'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/',
    name: 'index',
    component: layout,
    // redirect: '/Dashboard',
    // meta: { title: '首页', icon: 'svg-16' },
    hidden: true,
    children: [
      {
        path: '/Dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'svg-16' }
      }
    ]
  }
]

export const asyncRouter = [
  problemPage,
  tableManagement,
  fileTable,
  deviceManagement,
  systemManagement,
]

const createRouter = () =>
  new Router({
    mode: 'hash', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
